package zhoug.demo.chart2;

import android.graphics.Color;
import android.os.Bundle;
import android.view.View;

import zhoug.chart.utils.MPChartUtils;
import zhoug.demo.chart2.chart.BarChartActivity;
import zhoug.demo.chart2.chart.ChartTestActivity;
import zhoug.demo.chart2.chart.CombinedChartActivity;
import zhoug.demo.chart2.chart.HorienzontalBarChartActivity;
import zhoug.demo.chart2.chart.LineChartActivity;
import zhoug.demo.chart2.chart.MPHorizontalBarActivity;
import zhoug.demo.chart2.chart.MPIconActivity;
import zhoug.demo.chart2.chart.PieChartActivity;
import zhoug.demo.chart2.chart.RadarChartActivity;
import zhoug.logging.Logger;
import zhoug.common.adapters.recycler.BaseRecyclerViewAdapter;
import zhoug.common.adapters.recycler.TextAdapter;
import zhoug.common.adapters.recycler.dividers.ListItemDecoration;
import zhoug.common.router.Router;
import zhoug.common.utils.ToastUtils;

import java.util.Arrays;
import java.util.List;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.OrientationHelper;
import androidx.recyclerview.widget.RecyclerView;

/**
 * @Author: zhoug
 * @Date: 2024-01-30
 * @Description:
 */
public class MPChartActivity extends AppCompatActivity {
    private static final String TAG = ">>>CommonActivity";
    private RecyclerView mRecyclerView;
    private List<PageBean> data = Arrays.asList(
            new PageBean("示例", ChartTestActivity.class),
            new PageBean("Icon", MPIconActivity.class),
            new PageBean("占位图", PlaceHolderTestActivity.class),
            new PageBean("柱状图", BarChartActivity.class),
            new PageBean("水平柱状图", HorienzontalBarChartActivity.class),
            new PageBean("水平进度条(MPHorizontalBar)", MPHorizontalBarActivity.class),
            new PageBean("曲线图", LineChartActivity.class),
            new PageBean("混合图表", CombinedChartActivity.class),
            new PageBean("饼图", PieChartActivity.class),
            new PageBean("雷达图", RadarChartActivity.class)
    );

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mpchart);
        findViews();
        TextAdapter<PageBean> adapter = new TextAdapter<PageBean>() {
            @Override
            public String getText(PageBean bean) {
                return bean.text;
            }
        };
        adapter.setData(data);

        adapter.setOnItemClickListener(new BaseRecyclerViewAdapter.OnItemClickListener<PageBean>() {
            @Override
            public void onItemClick(BaseRecyclerViewAdapter<PageBean> adapter, View view, int position) {
                PageBean itemData = adapter.getItemData(position);
                if (itemData.cls != null) {
                    Router.navigation(MPChartActivity.this, itemData.cls);
                } else {
                    ToastUtils.toastLongCenter(getApplicationContext(), "没有配置页面");
                }
            }
        });

        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        mRecyclerView.addItemDecoration(new ListItemDecoration(this, OrientationHelper.VERTICAL));
        mRecyclerView.setAdapter(adapter);
        boolean add = true;
        int[] colors = add ? new int[8 + Colors.ColorLists.length] : new int[8];
        colors[0] = 0;
        colors[1] = Color.parseColor("#000000");
        colors[2] = Color.parseColor("#00000000");
        colors[3] = Color.parseColor("#ff000000");
        colors[4] = Color.parseColor("#000001");
        colors[5] = Color.parseColor("#ffffff");
        colors[6] = Color.parseColor("#00ffffff");
        colors[7] = Color.parseColor("#ffffffff");
        if (add) {
            if (Colors.ColorLists.length >= 0)
                System.arraycopy(Colors.ColorLists, 0, colors, 8, Colors.ColorLists.length);
        }


        for (int color : colors) {
            int color2 = MPChartUtils.setColorAlphaPercent(0.3f,color);
            Logger.d(TAG, MPChartUtils.colorToHex(color) + "->" + MPChartUtils.colorToHex(color2));


        }

    }

    private void findViews() {
        mRecyclerView = findViewById(R.id.recyclerView);

    }


}
